#include "GraphicsBox.h"

GraphicsBox::GraphicsBox(QGraphicsItem* parent, int index)
    : QGraphicsRectItem(parent)
    , index_(index)
    , scaleRate_(1)
{
}

GraphicsBox::~GraphicsBox() = default;

/**
 * @brief paint
 * @param painter
 * @param option
 * @param widget
 */

void GraphicsBox::paint(
    QPainter* painter,
    const QStyleOptionGraphicsItem* option,
    QWidget* widget
)
{
    QGraphicsRectItem::paint(painter, option, widget);

    painter->save();

    painter->setFont(QFont("Arial", 20 / scaleRate_));
    painter->drawText(rect(), Qt::AlignCenter, QString::number(index_));
    painter->restore();
}

void GraphicsBox::updateScaleRate(double scaleRate)
{
    scaleRate_ = scaleRate;
    setPen(QPen(Qt::red, 4 / scaleRate_));
    update();
}
